package com.example.huanhang.changzhouapp.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;

import com.allen.library.SuperTextView;
import com.example.huanhang.changzhouapp.R;
import com.example.huanhang.changzhouapp.base.BaseBackActivity;
import com.example.huanhang.changzhouapp.util.DeviceUtil;
import com.gyf.barlibrary.ImmersionBar;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author hang
 * @date 2017/11/2 0002
 */

public class ContantUsActivity extends BaseBackActivity {

    @BindView(R.id.contact_service_phone)
    SuperTextView contactServicePhone;
    @BindView(R.id.contact_business_phone)
    SuperTextView contactBusinessPhone;
    @BindView(R.id.contact_us_http)
    SuperTextView contactUsHttp;
    @BindView(R.id.contact_us_email)
    SuperTextView contactUsEmail;

    @Override
    public int getLayoutId() {
        return R.layout.activity_contant;
    }

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
        ButterKnife.bind(this);
        setTitle("联系我们");
        contactServicePhone.setOnSuperTextViewClickListener(superTextView -> intentTelePhone());
        contactBusinessPhone.setOnSuperTextViewClickListener(superTextView -> intentTelePhone());
        contactUsHttp.setOnSuperTextViewClickListener(superTextView -> {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            Uri contentUrl = Uri.parse("http://www.zzrseng.com");
            intent.setData(contentUrl);
            intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
            startActivity(intent);
        });
        contactUsEmail.setOnSuperTextViewClickListener(superTextView -> {
            Intent emailIntent = new Intent(Intent.ACTION_SEND);
            emailIntent.setType("message/rfc822");
            emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"zzrseng@qq.com"});
            startActivity(Intent.createChooser(emailIntent, "Choose an Email Client"));
        });
    }

    @Override
    public void initData() {

    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).statusBarColor(R.color.title).init();
    }

    /**
     * 判断是否为平板并进行跳转
     */
    private void intentTelePhone() {
        if (DeviceUtil.isTabletDevice(this)) {
            toast("设备无此功能");
        } else {
            Uri uri = Uri.parse("tel:0371-86008799");
            Intent intent = new Intent(Intent.ACTION_DIAL, uri);
            startActivity(intent);
        }
    }

}
